package demo;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class AviationInvoiceCalculator {

    /**
     * 计算计税依据金额（票价 + 燃油附加费）
     *
     * @param totalAmount 价税合计金额（票价 + 燃油附加费 + 机建费）
     * @param taxAmount   增值税额
     * @return 计税依据金额（票价 + 燃油附加费）
     */
    public static BigDecimal calculateTaxableAmount(BigDecimal totalAmount, BigDecimal taxAmount) {
        // 计税依据金额 = 增值税额 × (1 + 9%) / 9%
        BigDecimal taxableAmount = taxAmount
                .multiply(BigDecimal.valueOf(1.09))
                .divide(BigDecimal.valueOf(0.09), 2, RoundingMode.HALF_UP);

        // 由于计税依据金额 = 票价 + 燃油附加费 = 价税合计金额 - 机建费
        // 但机建费未知，这里直接返回计税依据金额
        return taxableAmount;
    }


    public static BigDecimal calculateTaxableAmount(BigDecimal totalAmount) {
        BigDecimal taxRate = new BigDecimal(0.0900000);
        return totalAmount.multiply(taxRate).setScale(2, RoundingMode.DOWN);
    }

    public static void main(String[] args) {
        // 示例数据1357.8
        BigDecimal totalAmount = new BigDecimal("1357.8"); // 价税合计金额
        BigDecimal taxAmount = new BigDecimal("36.7");  // 增值税额

        BigDecimal taxableAmount = calculateTaxableAmount(totalAmount.add(taxAmount));
        System.out.println("计税依据金额: " + taxableAmount + " 元");

        // 示例数据
        totalAmount = new BigDecimal("605.50"); // 价税合计金额
        taxAmount = new BigDecimal("36.7");  // 增值税额

        taxableAmount = calculateTaxableAmount(totalAmount.add(taxAmount));
        System.out.println("计税依据金额: " + taxableAmount + " 元");


        // 示例数据
        totalAmount = new BigDecimal("1522.94"); // 价税合计金额
        taxAmount = new BigDecimal("18.35");  // 增值税额

        taxableAmount = calculateTaxableAmount(totalAmount.add(taxAmount));
        System.out.println("计税依据金额: " + taxableAmount + " 元");
    }
}